package Chapter08.homework;

/**
 * @author 杨森
 * @date 2022年10月08日 19:07
 */
public class Homework01 {
    public static void main(String[] args) {
        Person[] person = new Person[3];
        person[0] = new Person("jack", 10, "JavaEE");
        person[1] = new Person("tom", 50, "python");
        person[2] = new Person("mary", 20, "Php");


        Person temp = null;
        for (int i = 0; i < person.length-1 ; i++) {
            for (int j = 0; j < person.length-1-i; j++) {
                if (person[i].getAge()<person[i+1].getAge()){
                    temp=person[i];
                    person[i]=person[i+1];
                    person[i+1]=temp;
                }
            }
        }
        for (int i = 0; i < person.length; i++) {
            System.out.println(person[i]);
        }
    }


}

class Person {
    String name;
    int age;
    String job;

    public Person() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Person{");
        sb.append("name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append(", job='").append(job).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
